<?php
// +----------------------------------------------------------------------
// | Yzncms [ 御宅男工作室 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://yzncms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | fastadmin: https://www.fastadmin.net/
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------
// | 安装主程序
// +----------------------------------------------------------------------

namespace app\admin\command;

use app\api\model\Order;
use PDO;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Db;
use think\Exception;
use think\facade\Config;
use think\facade\Request;
use think\facade\View;
use util\File;
use util\Random;

class Close extends Command
{
    /**
     * @var \think\Request Request 实例
     */
    protected $request;

    protected function configure()
    {
        $this->setName('close')
            ->setDescription('Command Close');
    }

    /**
     * 命令行安装
     */
    protected function execute(Input $input, Output $output)
    {

        echo "开始执行"."\n";

        $config = (new \app\admin\model\Config())->where(['id' => 15])->field('value')->find();
        //查询订单
        $makeCarOrder = (new Order())->where(['status' =>0])->select();
        $makeCarOrderId = [];
        foreach ($makeCarOrder as $value){
              $expireTime = $value['makeTime'];
              if($expireTime < time()){
                  $makeCarOrderId[] = $value['id'];


              }
        }

        echo  "开始执行关闭订单" . "\n";
        $closeOrder = (new Order())->where(['id' => $makeCarOrderId])->update(['status' => 4]);


        echo "执行完毕" ."\n";

    }

}
